package com.xm.servlet.reception_desk.shopping_cart;

import com.xm.service.reception_desk.ShoppingCartService;
import lombok.SneakyThrows;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 根据Id删除购物车商品
 * @author 康文程
 * @date 2024-1-4
 */
@WebServlet("/delete/shopping/cart")
public class DeleteShoppingCartServlet extends HttpServlet {
    private final ShoppingCartService shoppingCartService = new ShoppingCartService();

    /**
     * 根据Id删除商品
     * @param req   an {@link HttpServletRequest} object that
     *                  contains the request the client has made
     *                  of the servlet
     *
     * @param resp  an {@link HttpServletResponse} object that
     *                  contains the response the servlet sends
     *                  to the client
     *
     */
    @SneakyThrows(Exception.class)
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
        String shoppingCartId = req.getParameter("shoppingCartId");
        System.out.println(shoppingCartId);
        resp.getWriter().println(shoppingCartService.deleteFromShoppingCart(Integer.parseInt(shoppingCartId)));
    }
}
